package com.eqgis.eqtool.tmp;

import android.content.Context;

import com.eqgis.eqtool.cfg.LocalConfigManager;

import java.util.HashMap;

/**
 * ��������������
 * @create by tanyx 2021��6��30��16:08:00
 */
public class BaseParameterManager {
    private static BaseParameterManager baseParameterManager = null;
    private HashMap<String, String> resultMap;
    private LocalConfigManager instance;
    private String configName;

    BaseParameterManager() {
        instance = LocalConfigManager.getInstance();
        configName = "/app.cfg";
    }

    public static BaseParameterManager getInstance(){
        if (baseParameterManager == null){
            synchronized (BaseParameterManager.class){
                if (baseParameterManager == null){
                    baseParameterManager = new BaseParameterManager();
                }
            }
        }
        return baseParameterManager;
    }

    /**
     * ������������
     * @param configName
     */
    public void setConfigName(String configName) {
        if (!configName.endsWith(".cfg")){
            configName += ".cfg";
        }
        if (configName.contains("/")){
            this.configName = configName;
        }else {
            this.configName = "/" + configName;
        }
    }

    /**
     *
     * @param context
     * @param dataPath ����·��
     * @return
     */
    public BaseParameterManager init(Context context, String dataPath){
        EqLog.setPath(dataPath + "/log");
        CrashHandler.getInstance().setPath(dataPath + "/log").init(context);

        EqLog.delFile();
        instance.setLocalPath(dataPath + configName);

        instance.setLogListener(new LocalConfigManager.LogListener() {
            @Override
            public void loge(String s) {
            }

            @Override
            public void logi(String s) {
                EqLog.i(BaseParameterManager.class.getSimpleName(),s);
            }
        });
        //��������
        boolean b = instance.loadConfig(context);
        if (b){
            resultMap = instance.getResultMap();
        }
        return this;
    }

    public HashMap<String, String> getMap() {
        return resultMap;
    }
}
